<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/1/7
 * Time: 15:39
 */
defined('IN_TS') or die('Access Denied.');
$userid = aac('user')->isLogin();

switch($ts){


    //提现记录
    case "":

        $strUser = aac('user')->getOneUser($userid);

        $arrTixian = $new['pay']->findAll('pay_tixian',array(
            'userid'=>$userid,
        ),'addtime desc');


        $title = '提现记录';
        include template('tixian');
        break;


    //申请提现
    case "shenqing":

        $js = intval($_GET['js']);

        $price = sprintf("%01.2f",$_POST['price']);

        if($price==0.00){
            getJson('请输入提现金额');
        }

        //判断微信号是否输入
        $strUserInfo = $new['pay']->find('user_info',array(
            'userid'=>$userid,
        ),'weixin');

        if($strUserInfo['weixin']==''){
            getJson('没有输入提现微信号！',$js,2,tsUrl('my','setting',array('ts'=>'base')));
        }


        //计算资金账户
        $strPay = aac('pay')->getUserPay($userid);


        //计算冻结金额
        //$strDongjie = $db->once_fetch_assoc("select sum(price) as allprice from ".dbprefix."developer_yuyue where `touserid`='$userid'  and (`status`='1' or `status`='2')");

        //$tixianPrice = $strPay['over']-$strDongjie['allprice'];
        $tixianPrice = $strPay['over'];


        if($tixianPrice==0){
            getJson('可提现金额为0，不可以提现！');
        }

        if($price>$tixianPrice){
            getJson('提现金额大于可提现余额，不可以提现！');
        }


        //一天仅能申请一次提现
        $strTixian = $new['pay']->find('pay_tixian',array(
            'userid'=>$userid,
        ),'addtime desc');

        if($strTixian && date('Y-m-d',$strTixian['addtime'])==date('Y-m-d')){
            getJson('一天内仅可以提现一次！');
        }


        if($strTixian && $strTixian['status']==0){
            getJson('你有提现申请还未处理，暂时不可以提现！');
        }


        $new['pay']->create('pay_tixian',array(
            'userid'=>$userid,
            'price'=>$price,
            'addtime'=>time(),
        ));


        getJson('提现申请提交成功！',$js,2,tsUrl('pay','tixian'));


        break;

}